﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using GamePlugin.IO;
using System.IO;

namespace GamePlugin.Logics.Data
{
    public class ImageStorage
    {
        private static Dictionary<string, Bitmap> _ImageDictionary = new Dictionary<string, Bitmap>();

        public static Bitmap GetBitmap(string name)
        {
            if (_ImageDictionary.ContainsKey(name))
                return _ImageDictionary[name];

            string folder = System.IO.Directory.GetCurrentDirectory();
            System.Drawing.Image allPick = null;
            if (Path.GetPathRoot(name).Length > 0)
                allPick = System.Drawing.Bitmap.FromFile(name);
            else
                allPick = System.Drawing.Bitmap.FromFile(IOManager.Instance.ImagesFolderPath + "//" + name);

            System.Drawing.Bitmap target = new Bitmap(allPick);
            target = target.Clone(new Rectangle(0, 0, target.Width, target.Height), System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            _ImageDictionary.Add(name, target);
            return target;
        }
    }
}
